home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerMacOberon feb96 / Source / TextPreview.Mod (.txt) < prev    next >
Encoding:
Oberon Text  |  1996-01-29  |  7.8 KB  |  181 lines  |  [TEXT/.Ob4]

  1. Syntax10.Scn.Fnt
  2. Syntax12.Scn.Fnt
  3. Syntax10i.Scn.Fnt
  4. Syntax10b.Scn.Fnt
  5. MODULE TextPreview;    (** CAS 19-May-92 (Rel. 2.42) **)
  6.     IMPORT
  7.         Texts, Viewers, Oberon, Printer, MenuViewers, TextFrames, TextPrinter, TextPFrames;
  8.     CONST
  9.         Version = "TextPreview  1.0  (cas 19 May 92)";
  10.         Menu = "System.Close  System.Copy  System.Grow  TextPreview.Synch  Edit.Store ";
  11.         mm = TextFrames.mm; Scale = mm DIV 10; Unit = TextPrinter.Unit;
  12.         bodyX = 15 * mm DIV Unit; bodyY = 15 * mm DIV Unit;
  13.         bodyW = 165 * mm DIV Unit; bodyH = 260 * mm DIV Unit;
  14.         W: Texts.Writer;
  15.     PROCEDURE Ch (ch: CHAR);
  16.     BEGIN Texts.Write(W, ch); Texts.Append(Oberon.Log, W.buf)
  17.     END Ch;
  18.     PROCEDURE Str (s: ARRAY OF CHAR);
  19.     BEGIN Texts.WriteString(W, s); Texts.Append(Oberon.Log, W.buf)
  20.     END Str;
  21.     PROCEDURE Int (n: LONGINT);
  22.     BEGIN Texts.Write(W, " "); Texts.WriteInt(W, n, 0); Texts.Append(Oberon.Log, W.buf)
  23.     END Int;
  24.     PROCEDURE Ln;
  25.     BEGIN Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
  26.     END Ln;
  27.     (* arguments *)
  28.     PROCEDURE GetMainArg (VAR S: Texts.Scanner; text: Texts.Text; org: LONGINT; VAR beg, end: LONGINT);
  29.         VAR time: LONGINT;
  30.     BEGIN Texts.OpenScanner(S, text, org); Texts.Scan(S); beg := org; end := text.len;
  31.         IF (S.class = Texts.Char) & (S.c = "^") THEN Oberon.GetSelection(text, beg, end, time);
  32.             IF time >= 0 THEN Texts.OpenScanner(S, text, beg); Texts.Scan(S) ELSE end := 0 END
  33.         END;
  34.         IF S.line # 0 THEN S.class := Texts.Inval END
  35.     END GetMainArg;
  36.     PROCEDURE ScanArgs (VAR S: Texts.Scanner; VAR pno, first, last, bx, by, bw, bh: INTEGER);
  37.         VAR i, k: INTEGER; ch: CHAR;
  38.     BEGIN
  39.         bx := bodyX; by := bodyY; bw := bodyW; (* bh := bodyH; *)
  40.         bh := SHORT((LONG(Printer.PageHeight) * Unit - 37 * mm) DIV Unit);
  41.         pno := 0; first := 0; last := 10000;
  42.         WHILE (S.class = Texts.Char) & (S.c = "/") DO Texts.Scan(S);
  43.             IF S.class = Texts.Name THEN ch := CAP(S.s[0]); Texts.Scan(S);
  44.                 IF ch = "A" THEN
  45.                 ELSIF (ch = "C") & (S.class = Texts.Int) & (1 <= S.i) & (S.i < 10) THEN Texts.Scan(S)
  46.                 ELSIF (ch = "F") & (S.class = Texts.Name) THEN Texts.Scan(S)
  47.                 ELSIF ch = "H" THEN
  48.                     IF (S.class = Texts.Name) OR (S.class = Texts.String) THEN Texts.Scan(S) END
  49.                 ELSIF ch = "M" THEN    (*margin options*)
  50.                     IF S.class = Texts.Name THEN ch := CAP(S.s[0]); Texts.Scan(S); i := 0;
  51.                         WHILE (S.class = Texts.Int) & (0 <= S.i) DO
  52.                             k := SHORT(S.i * Scale DIV TextPrinter.Unit); INC(i); Texts.Scan(S);
  53.                             IF ch = "H" THEN
  54.                             ELSIF ch = "B" THEN
  55.                                 IF i = 1 THEN bx := k ELSIF i = 2 THEN by := k
  56.                                 ELSIF i = 3 THEN bw := k ELSIF i = 4 THEN bh := k
  57.                                 END
  58.                             END
  59.                         END
  60.                     END
  61.                 ELSIF ch = "P" THEN    (*page options*)
  62.                     IF (S.class = Texts.Int) & (0 <= S.i) THEN pno := SHORT(S.i); first := pno; Texts.Scan(S)
  63.                     ELSIF S.class = Texts.Name THEN ch := CAP(S.s[0]); Texts.Scan(S)
  64.                     END
  65.                 ELSIF (ch = "S") & (S.class = Texts.Int) & (0 <= S.i) THEN first := SHORT(S.i); Texts.Scan(S);
  66.                     IF (S.class = Texts.Int) & (0 <= S.i) THEN last := SHORT(S.i); Texts.Scan(S) ELSE last := first END
  67.                 END
  68.             END
  69.         END
  70.     END ScanArgs;
  71.     (* pagination *)
  72.     PROCEDURE OpenDmyPrinter;
  73.         VAR name: ARRAY 32 OF CHAR;
  74.     BEGIN name := "Out.Prt"; Printer.Open(name, Oberon.User, Oberon.Password);
  75. (*        IF Printer.res # 0 THEN HALT(99) END    *)
  76.     END OpenDmyPrinter;
  77.     PROCEDURE LocatePageBreaks (text: Texts.Text; pno, first, last, bx, by, bw, bh: INTEGER;
  78.             VAR pages: INTEGER; VAR porg: ARRAY OF LONGINT);
  79.         VAR org: LONGINT;
  80.     BEGIN org := 0; pages := 0;
  81.         WHILE (org < text.len) & (Printer.res = 0) DO
  82.             IF pages < LEN(porg) THEN porg[pages] := org END;
  83.             IF (first <= pno) & (pno <= last) THEN INC(pages) END;
  84.             TextPrinter.PlaceBody(bx, by, bw, bh, text, org, pno, FALSE);
  85.             Ch("."); INC(pno)
  86.         END
  87.     END LocatePageBreaks;
  88.     PROCEDURE CountPages (text: Texts.Text; pno, first, last, bx, by, bw, bh: INTEGER; VAR pages: INTEGER);
  89.         VAR porg: ARRAY 1000 OF LONGINT;
  90.     BEGIN LocatePageBreaks(text, pno, first, last, bx, by, bw, bh, pages, porg)
  91.     END CountPages;
  92.     (* commands *)
  93.     PROCEDURE Synch*;
  94.         VAR V: Viewers.Viewer; F: TextPFrames.Frame;
  95.     BEGIN F := Oberon.Par.vwr.dsc.next(TextPFrames.Frame);
  96.         V := Oberon.MarkedViewer();
  97.         IF (V IS MenuViewers.Viewer) & (V.dsc.next IS TextFrames.Frame) THEN
  98.             IF V.dsc.next IS TextPFrames.Frame THEN
  99.                 TextPFrames.Show(V.dsc.next(TextPFrames.Frame), F.org)
  100.             ELSIF V.dsc.next IS TextFrames.Frame THEN
  101.                 TextFrames.Show(V.dsc.next(TextFrames.Frame), F.org)
  102.             ELSE TextFrames.Show(V.dsc.next(TextFrames.Frame), F.org)
  103.             END
  104.         END
  105.     END Synch;
  106.     PROCEDURE This*;
  107.         VAR S: Texts.Scanner; V: Viewers.Viewer; F: TextFrames.Frame; beg, end: LONGINT; x, y: INTEGER;
  108.     BEGIN GetMainArg(S, Oberon.Par.text, Oberon.Par.pos, beg, end);
  109.         IF (S.class = Texts.Char) & (S.c = "*") THEN V := Oberon.MarkedViewer();
  110.             IF (V IS MenuViewers.Viewer) & (V.dsc.next IS TextFrames.Frame) THEN
  111.                 IF V.dsc IS TextFrames.Frame THEN
  112.                     Texts.OpenScanner(S, V.dsc(TextFrames.Frame).text, 0); Texts.Scan(S)
  113.                 ELSE S.s := "TextPreview.Text"
  114.                 END;
  115.                 F := V.dsc.next(TextFrames.Frame);
  116.                 Oberon.AllocateUserViewer(Oberon.Mouse.X, x, y);
  117.                 V := MenuViewers.New(TextFrames.NewMenu(S.s, Menu),
  118.                     TextPFrames.NewText(F.text, F.org), TextFrames.menuH, x, y)
  119.             END
  120.         END
  121.     END This;
  122.     PROCEDURE Paginate*;
  123.         VAR S: Texts.Scanner; V: Viewers.Viewer; F: TextPFrames.Frame; beg, end: LONGINT;
  124.             pages, h, pno, first, last, bx, by, bw, bh: INTEGER; porg: ARRAY 1000 OF LONGINT;
  125.     BEGIN GetMainArg(S, Oberon.Par.text, Oberon.Par.pos, beg, end);
  126.         IF (S.class = Texts.Char) & (S.c = "*") THEN Str("TextPreview.Paginate * "); Texts.Scan(S);
  127.             V := Oberon.MarkedViewer();
  128.             IF (V IS MenuViewers.Viewer) & (V.dsc.next IS TextPFrames.Frame) THEN
  129.                 OpenDmyPrinter;
  130.                 ScanArgs(S, pno, first, last, bx, by, bw, bh);
  131.                 F := V.dsc.next(TextPFrames.Frame);
  132.                 LocatePageBreaks(F.text, pno, first, last, bx, by, bw, bh, pages, porg);
  133.                 TextPFrames.SetPagination(F, pages, pno, bw, porg); Int(pages);
  134.                 h := F.H; TextPFrames.Resize(F, F.X, F.Y, F.W, 0); TextPFrames.Resize(F, F.X, F.Y, F.W, h)
  135.             ELSE Str("failed (* not a preview)")
  136.             END;
  137.             Ln
  138.         END
  139.     END Paginate;
  140.     PROCEDURE PageCount*;
  141.         VAR S: Texts.Scanner; V: Viewers.Viewer; text: Texts.Text; beg, end: LONGINT;
  142.             pages, total, pno, first, last, bx, by, bw, bh: INTEGER;
  143.     BEGIN Str("TextPreview.PageCount"); Ln;
  144.         GetMainArg(S, Oberon.Par.text, Oberon.Par.pos, beg, end);
  145.         OpenDmyPrinter;
  146.         IF (S.class = Texts.Char) & (S.c = "*") THEN Texts.Scan(S);
  147.             V := Oberon.MarkedViewer();
  148.             IF (V # NIL) & (V IS MenuViewers.Viewer) & (V.dsc.next IS TextFrames.Frame) THEN
  149.                 ScanArgs(S, pno, first, last, bx, by, bw, bh);
  150.                 text := V.dsc.next(TextFrames.Frame).text(Texts.Text);
  151.                 IF V.dsc IS TextFrames.Frame THEN
  152.                     Texts.OpenScanner(S, V.dsc(TextFrames.Frame).text, 0); Texts.Scan(S);
  153.                     IF S.class # Texts.Name THEN S.s[0] := "*"; S.s[1] := 0X END
  154.                 ELSE S.s[0] := "*"; S.s[1] := 0X
  155.                 END;
  156.                 Str("  "); Str(S.s); Str(" counting ");
  157.                 CountPages(text, pno, first, last, bx, by, bw, bh, pages);
  158.                 Int(pages); Ln
  159.             ELSE Str(" failed (bad * marker)"); Ln
  160.             END
  161.         ELSIF S.class = Texts.Name THEN
  162.             text := TextFrames.Text(S.s);
  163.             Str("  "); Str(S.s); Str(" counting ");
  164.             Texts.Scan(S); ScanArgs(S, pno, first, last, bx, by, bw, bh);
  165.             CountPages(text, pno, first, last, bx, by, bw, bh, pages);
  166.             Int(pages); Ln
  167.         ELSE total := 0;
  168.             ScanArgs(S, pno, first, last, bx, by, bw, bh);
  169.             WHILE (S.class = Texts.Name) & (beg < end) DO
  170.                 Str("  "); Str(S.s); Str(" counting ");
  171.                 text := TextFrames.Text(S.s);
  172.                 beg := Texts.Pos(S); Texts.Scan(S);
  173.                 CountPages(text, pno, first, last, bx, by, bw, bh, pages); INC(total, pages);
  174.                 Int(pages); Ln
  175.             END;
  176.             Str("  total"); Int(total); Ln
  177.         END
  178.     END PageCount;
  179. BEGIN Texts.OpenWriter(W); Str(Version); Ln
  180. END TextPreview.
  181.